package com.sds.batch.sample;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

public class SimpleCalledTasklet implements InitializingBean, Tasklet{
	private Logger logger = LoggerFactory.getLogger(SimpleCalledTasklet.class);
	private int count=0;

	@Override
	public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
			throws Exception {
		// TODO Auto-generated method stub
		Assert.state(count==1);
		logger.info("======================================");
		logger.info(this.getClass().getSimpleName() + "'s execute called' ["
				+ count++ + "]");
		logger.info("======================================");
		Assert.state(count==2);
		
		logger.info("#########################################");
		logger.info("Job Name       : " + arg1.getStepContext().getJobName());
		logger.info("Step Name      : " + arg1.getStepContext().getStepName());
		logger.info("Job Parameters : " + arg1.getStepContext().getJobParameters().toString());
		logger.info("#########################################");
		
		return RepeatStatus.FINISHED;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		logger.info("======================================");
		logger.info(this.getClass().getSimpleName() + "'s afterPropertiesSet called' ["
				+ count++ + "]");
		logger.info("======================================");
	}

}
